package com.forhappy.light3ds8;

import com.forhappy.light3ds8.arm.bluetooth.ArmMgr;
import com.forhappy.light3ds8.server.HttpUtils;
import com.forhappy.light3ds8.server.HttpUtils.PostCallBack;
import com.forhappy.light3ds8.server.HttpUtils.Result;
import com.forhappy.light3ds8.tools.DatasUtils;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
//	public static final String ORG_SEND_DATAS =
//			"01 02 03 04 05 06 07 08";

	EditText eSendText = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        eSendText = (EditText) findViewById(R.id.eSendDatas);
        eSendText.setText(DatasUtils.byteToHexStr(DatasUtils.getFlorToFlorDatas()));

        Button bSendDatas = (Button) findViewById(R.id.bStart);
        bSendDatas.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				ArmMgr.sendDatas(DatasUtils.hexStrToBytes(eSendText.getText().toString()));
			}
		});
        
        Button bGetDatas = (Button) findViewById(R.id.bGetDatas);
        bGetDatas.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				HttpUtils.post("http://www.baidu.com", null, 
					new PostCallBack() {
						@Override
						public void onReceived(Result res) {
							setText(res.toString());
						}
					});
			}
		});
    }
    private void setText(final String msg){
    	eSendText.post(new Runnable() {
			@Override
			public void run() {
				eSendText.setText(msg);
			}
		});
    }

}
